var e = getApp(), t = e.requirejs("core"), a = e.requirejs("jquery"), foxui = e.requirejs("foxui");

Page({
    data: {
        images: [],
        imgs: [],
        show:0,
        money:'',
        paystatus: 0,
        levelid:0,
        coupon: {
          count: 0
        },
        submit: !0,
    },
    onLoad: function(t) {
        e.url(t), this.get_list();
    },
    onShow: function() {
        var t = e.getCache("coupon");
        this.setData({
            "coupon.id": t.id,
            "coupon.name": t.name || ""
        });
    },
    get_list: function() {
        var e = this;
        t.get("member/yrecharge", {}, function(t) {
            t.show = !0, e.setData(t);
        });
    },
    radioChange:function(c){
      console.log(c);
      
      var id=c.detail.value;
      this.setData({payid:id});
    },
    radioChange1:function(c){
      console.log(c);
      
      var id=c.detail.value;

      this.setData({levelid:id});
    },
    copy:function(c){
      console.log(c);
      var text=c.target.dataset.id
      wx.setClipboardData({
          data: text,
          success: function (res) {
          }
      })
    },
    toggle: function(e) {
        var a = t.pdata(e), i = a.id, o = a.type, n = {};
        n[o] = 0 == i || void 0 === i ? 1 : 0, this.setData(n);
    },
    upload: function(t1) {
      var e = this, s = t.data(t1), i = s.type, o = e.data.images, n = e.data.imgs, r = s.index;
      "image" == i ? t.upload(function(t) {
          n=[];
          o=[];
          o.push(t.filename), n.push(t.url), e.setData({
              images: o,
              imgs: n
          });
      }) : "image-remove" == i ? (o.splice(r, 1), n.splice(r, 1), e.setData({
          images: o,
          imgs: n
      })) : "image-preview" == i && wx.previewImage({
          current: n[r],
          urls: n
      });
  }
  ,
    money: function(e) {
        var o = a.trim(e.detail.value), n = this;
        n.setData({
          money: o,
        });
    },
    preview: function(ev) {
      
      var imgList =[];
          imgList.push(ev.target.dataset.src);
       var src= ev.target.dataset.src
  
      wx.previewImage({
        current: src,
        urls: imgList,
        success: function(res) {
          console.log('success');
        },
        fail: function(res) {
          console.log('fail');
        },
      })
    },
    submit: function() {
        var that=this;
        var e = a.toFixed(this.data.money, 2), i = {};
        // 重复提交
        if(that.data.submit){
          if(!that.data.payid) {
            foxui.toast(that, "请选择充值方式"); return;
          }
          if(!that.data.levelid) {
            foxui.toast(that, "请选择充值等级"); return;
          }
          if(that.data.images.length<1){
            foxui.toast(that, "请上传支付凭证"); return;
          }
          i.paytype = that.data.payid,
          
          i.levelid=that.data.levelid,
          i.paythumb= that.data.images,
          i.money = e;
          that.setData({ submit: !1 })
          t.post("member/yrecharge/submit", i, function(e) {

            if(0 == e.error ){
              that.setData({
                'money': '',
                'images':[],
                'imgs':[],
              });
              foxui.toast(that, '提交成功,等待审核');
            } else {
              foxui.toast(that, e.message);
              that.setData({ submit: !0 })
            } 
          }, !0);
        }
        // this.data.disabled || (void 0 === e || isNaN(e) ? t.alert("请填写正确的充值金额!") : e <= 0 || this.data.disabled ? t.alert("最低充值金额为" + this.data.minimumcharge + "元!") : (i.money = e, 
    }
});